package message.entity;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;

public class MsgConfig {

    private Element documentElement;

    private String msgType;

    private String encoding = "UTF-8";

    private String rootName;


    public MsgConfig(String filePath) throws DocumentException {
        File file = new File(filePath);
        SAXReader reader = new SAXReader();
        Document doc = reader.read(file);
        Element rootElement = doc.getRootElement();
        this.documentElement = rootElement.element("Document");
        this.msgType = this.documentElement.attribute("type").getValue();
        String encoding = this.documentElement.attribute("encoding").getValue();
        if(encoding != null && !encoding.isEmpty()){
            this.encoding = encoding;
        }
        this.rootName = this.documentElement.attribute("root").getValue();
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public Element getDocumentElement() {
        return documentElement;
    }

    public void setDocumentElement(Element documentElement) {
        this.documentElement = documentElement;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public String getRootName() {
        return rootName;
    }

    public void setRootName(String rootName) {
        this.rootName = rootName;
    }
}
